module.exports =  {
  buttons: [
    {
      text: '添加',
      type: 'danger',
      handler: ({ tableContext: { setAddFormVisiable } }) => setAddFormVisiable(true)
    },
    {
      text: '删除',
      handler: () => alert(`删除`)
    }
  ],
  queryForm: {
    content: '测试内容111',
    config: {
      inline: true
    },
    rules: {
      tpName: [
        {
          pattern: /\w{3,5}/,
          message: 'must 3~5'
        },
        {
          required: true,
          message: '必填信息'
        }
      ],
      tpId: [
        {
          validator(rule, value) {
            return value > 5 && value < 8
          },
          transform(val) {
            return val
          },
          message: 'must 5~8'
        }
      ]
    },
    items: [
      { label: '类型名称', prop: 'tpName', size: 'small' },
      { label: '类型编号', prop: 'tpId', type: 'number' },
      {
        label: '性别',
        prop: 'sex',
        type: 'radio',
        style: { width: '150px' },
        options: [
          { label: '男', value: 'man' },
          { label: '女', value: 'woman' }
        ]
      },
      {
        label: '爱好',
        prop: 'loves',
        type: 'checkbox',
        options: [
          { label: '摄影', value: 'sheying' },
          { label: '电影', value: 'dianying' }
        ]
      }
    ],
    defaultValue: {
      
    },
    buttons: [
      {
        text: '确定',
        emitName: 'confirm',
        type: 'primary',
        handler: ({ model, formRef }) => {
          formRef.value.validate(function (isValid, fieldError) {
            if (!isValid) {
              console.error(fieldError)
            }
          })
        }
      },
      {
        text: '取消',
        emitName: 'cancle',
        type: 'warning',
        handler: function ({ formRef }) {
          formRef.value.resetFields()
        }
      }
    ]
  },
  addForm: {
    title: `添加人口`,
    beforeClose(done) {
      done()
    },
    dialogConfig: {
      width: '500px',
      draggable: true
    },
    formConfig: {
      items: [
        { label: '姓名', prop: 'name', size: 'small' },
        { label: '年龄', prop: 'age', type: 'number' },
        {
          label: '性别',
          prop: 'sex',
          type: 'radio',
          style: { width: '150px' },
          options: [
            { label: '男', value: 'man' },
            { label: '女', value: 'woman' }
          ]
        },
        {
          label: '爱好',
          prop: 'loves',
          type: 'checkbox',
          options: [
            { label: '摄影', value: 'sheying' },
            { label: '电影', value: 'dianying' }
          ]
        }
      ],
      defaultValue: {
        age: 88,
        sex: 'man',
        loves: ['dianying']
      },
      buttons: [
        {
          text: '确定',
          emitName: 'confirm',
          type: 'primary',
          handler: ({ model }) => console.log(`this age is ${model.age}`)
        },
        {
          text: '取消',
          emitName: 'cancle',
          type: 'warning',
          handler: function ({ formRef, tableContext: { setAddFormVisiable } }) {
            setAddFormVisiable(false)
          }
        },
        {
          text: '重置',
          type: 'info',
          handler: function ({ formRef }) {
            formRef.value.resetFields()
          }
        }
      ]
    }
  },
  editForm: {
    title: '编辑信息',
    dialogConfig: {
      width: '500px'
    }
  },
  table: {
    stripe: true,
    size: 'small',
    selection: true,
    actionColumn: {
      width: 300,
      label: '操作列'
    },
    columns: [
      { prop: 'tp_id', label: '类型编号', width: '100' },
      {
        prop: 'tp_name',
        label: '类型名称',
        width: '200',
        link: ({ tp_name }) => `/Home?name=${tp_name}`
      },
      {
        prop: 'tp_code',
        label: '类型编号',
        width: '200',
        filter: (row, prop) => `${row['tp_id']}--${row[prop]}`
      },
      {
        prop: 'base_type',
        label: '基本类型',
        width: '250',
        tag: (row, prop) => ({ type: 'success', text: row['base_type'] })
      },
      { prop: 'default_value', label: '默认值', width: '250' }
    ],
    buttons: [
      {
        text: '添加',
        type: 'primary',
        handler: ({ setAddFormVisiable }) => {
          setAddFormVisiable(true)
        }
      },
      { text: '编辑', handler: ({ setEditFormVisiable }) => setEditFormVisiable(true) },
      { text: '删除', handler: (_,{$index,row}) => console.log(`添加`,$index,row['base_type']) }
    ],
    pagin: {
      init: {
        currentPage: 1,
        pageSizes: [10, 20, 30, 40],
        pageSize: 10
      },
      layout: 'total, sizes, prev, pager, next, jumper',
      prevText: '上一页',
      nextText: '下一页'
    }
  },
  handlers: {
    onMounted(data, total, { api: { fetchPage }, paginInfo: { pageSize = 10, currentPage = 1 } }) {
      fetchPage({
        pageSize: pageSize.value,
        currentPage: currentPage.value
      }).then(function (res) {
        data.value = res.data.rows
        total.value = res.data.amount
      })
    },
    onPaginChange(data, tableContext, size, current, total) {
      if (size) {
        tableContext.paginInfo.pageSize.value = size
      }
      // if(current){
      //   tableContext.paginInfo.currentPage.value=current
      // }
      this.onMounted(data, total, tableContext)
    }
  }
}
